<div class="main-title main-title-with-tabs">
    <h1 class="float-left">Chart of Accounts</h1>
	<span class="controls">
        <a id="addAccount" class="link-button with-icon" href="<?php echo $this->createUrl('accounting/addAccount'); ?>">
            <img src="/images/icons/fugue/plus.png" />
            Add Account
        </a>
    </span>
	<?php if (Yii::app()->user->model->agency->party->hasGlAccounts()): ?>
		<div class="main-title-tabs">
			<br/>
			<p>You can modify your Chart of Accounts by adding, editing or deleting accounts from the list below.</p>
			<?php
			$this->widget('zii.widgets.CMenu', array(
				'items' => array(
					array(
						'label' => 'All Accounts',
						'url' => array($this->route, 'view' => ''),
						'active' => $view == ''
					),
					array(
						'label' => 'Assets',
						'url' => array($this->route, 'view' => 'Asset'),
						'active' => $view == 'assets'
					),
					array(
						'label' => 'Liabilities',
						'url' => array($this->route, 'view' => 'Liability'),
						'active' => $view == 'assets'
					),
					array(
						'label' => 'Income',
						'url' => array($this->route, 'view' => 'Income'),
						'active' => $view == 'income'
					),
					array(
						'label' => 'Expenses',
						'url' => array($this->route, 'view' => 'Expense'),
						'active' => $view == 'expenses'
					),
					array(
						'label' => 'Equity',
						'url' => array($this->route, 'view' => 'Equity'),
						'active' => $view == 'equity'
					),
				),
				'encodeLabel' => false,
				'htmlOptions' => array(
					'class' => '',
				),
			));
			?>
		</div>
	<?php endif; ?>
</div>
<?php if (!Yii::app()->user->model->agency->party->hasGlAccounts()): ?>
	<div class="grid_16 section highlighted">
		<div class="block">
			<h2>
				<img src="/images/icons/farmfresh/32x32/error.png" />
				Setup Required
			</h2>
			<p>The Chart of Accounts is a list of all the accounts used to code your transactions. You need to add some accounts before you can create Invoices, Receipts and Payment Vouchers.</p>
			<p>You can use PropSage's default accounts or add your own:</p>
			<div>
				<a class="link-button with-icon green no-margin" href="<?php echo $this->createUrl('accounting/addDefaultAccounts'); ?>"><img src="/images/icons/fugue/report--plus.png" />Add Default Accounts</a>
				<a class="link-button with-icon no-margin" href="<?php echo $this->createUrl('accounting/addAccount'); ?>"><img src="/images/icons/fugue/report--plus.png" />Add Account</a>
				<a class="link-button with-icon no-margin" href="<?php echo $this->createUrl('accounting/importAccounts'); ?>"><img src="/images/icons/fugue/report--plus.png" />Import from File</a>
			</div>
		</div>
	</div>
<?php else: ?>
	<div class="grid_16">
		<?php
		$form = $this->beginWidget('CActiveForm', array(
			'id' => 'chartOfAccounts-form',
			'enableAjaxValidation' => FALSE
				));
		?>
		<div class="admin-accounting">		
			<?php
			$this->widget('PsGridView', array(
				'id' => 'chart_of_accounts_grid',
				'dataProvider' => $dataProvider,
				'template' => '{pagesize}{pager}{items}',
				'pagesizeCssClass' => 'pager-pagesize',
				'itemsCssClass' => 'items clear',
				'emptyText' => 'No accounts found.',
				'selectableRows' => 0,
//            'selectionChanged' => "propsage.propertycase.index.onGridViewSelectionChanged",
				'columns' => array(
					'id' => array(
						'class' => 'CCheckBoxColumn',
						'name' => 'id',
						'selectableRows' => 2
					),
					'code',
					'name',
					'type' => array(
						'header' => 'Type',
						'name' => 'gl_account_type_code'
					),
					'description',
					'buttons' => array(
						'class' => 'CButtonColumn',
						'template' => '{update}{delete}',
						'buttons' => array(
							'update' => array(
								'url' => 'array("accounting/updateAccount/", "id" => $data->id)'
							),
							'delete' => array(
								'url' => 'array("accounting/deleteAccount/", "id" => $data->id)',
							)
						),
						'afterDelete' => 'prestige.admin.accounting.chartOfAccounts.onGridAfterDelete',
					)
				)
			));
			?>
			<button id="btnDeleteSelected" class="link-button no-margin with-icon" type="submit" name="action" value="Delete">
				<img src="/images/icons/fugue/minus-circle.png" />Delete Selected
			</button>
		</div>
		<?php $this->endWidget(); ?>
	</div>
<?php endif; ?>